package com.hb.trade.server.project.section.manager;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.extra.spring.SpringUtil;
import com.hb.core.pojo.enums.ProblemStatusEnum;
import com.hb.core.pojo.project.section.dto.ProblemDTO;
import com.hb.core.pojo.project.section.entity.Problem;
import org.fzzn.core.util.Enums;

import java.util.List;

/**
 * 供应商提出问题记录Manager
 *
 * @author Lix1ang
 * @date 2021-12-13 17:13:16
 */
public class ProblemManager extends ProblemDTO {

    public String paramsValid() {
        if (null == this.getSectionId()){
            return "标段id不能为空";
        }
        if (StrUtil.isEmpty(this.getTitle())){
            return "问题标题不能为空";
        }
        if (StrUtil.isEmpty(this.getContent())){
            return "问题内容不能为空";
        }
        return null;
    }

    public String replyProblemValid() {
        if (null == this.getSectionId()){
            return "标段id不能为空";
        }
        if (null == this.getParentId()){
            return "父级id不能为空";
        }
        if (StrUtil.isEmpty(this.getContent())){
            return "回复内容不能为空";
        }
        return null;
    }

    public String receiptProblemValid() {
        if (null == this.getSectionId()){
            return "标段id不能为空";
        }
        if (null == this.getParentId()){
            return "父级id不能为空";
        }
        if (StrUtil.isEmpty(this.getContent())){
            return "回执内容不能为空";
        }
        return null;
    }

    /**
     * problemList 转换 ProblemDto
     * @param problemList
     * @param bidFlag 是否是投标人
     * @return
     */
    public static List<ProblemDTO> changeProblemDto(List<Problem> problemList, boolean bidFlag){
        List<ProblemDTO> problemDtoList = CollUtil.list(false);
        if (CollUtil.isEmpty(problemList)){
            return problemDtoList;
        }
        for (Problem problem : problemList) {
            ProblemDTO problemDto  = problem.to(ProblemDTO.class);
            if (bidFlag){//投标人
                problemDto.setStatusName(Enums.nameOf(ProblemStatusEnum.class,problemDto.getStatus()));
                problemDtoList.add(problemDto);
                continue;
            }
            String statusName = "";
            //招标人的状态显示
            if (ProblemStatusEnum.ISSUED.getCode() == problem.getStatus()){
                statusName = "待回复";
            }else if (ProblemStatusEnum.TO_BE_CONFIRMED.getCode() == problem.getStatus()){
                statusName = "已回复";
            }else if (ProblemStatusEnum.CONFIRMED.getCode() == problem.getStatus()){
                statusName = "已确认";
            }else {
                statusName = "已确认";
            }
            problemDto.setStatusName(statusName);
            problemDtoList.add(problemDto);
        }
        return problemDtoList;
    }
}
